package com.hoperun.preparedisplay.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.os.Environment;
import android.util.Xml;

public class Setting {
	
//	private static String URL = "http://10.10.151.74:8080/szerp/PublicWebServiceInterface";
	//private static String URL = "http://10.10.142.64:8080/szerpynhj/PublicWebServiceInterface";
	private static String URL = "http://10.10.115.138:8080/szerpynhj/PublicWebServiceInterface";
//	private static String URL = "http://192.168.1.118:8063/szerpynhj/PublicWebServiceInterface";
//	private static String URL = "http://192.168.1.125:8080/szerpynhj/PublicWebServiceInterface";
	
	private static int SOCKET_TIMEOUT  = 5000;
	private static int REQUEST_RATE    = 5000;
	private static int FRESH_PAGE_RATE = 5000;
	private static int ROW_NUM = 7;
	private static int COLUMN_NUM = 10;
	private static String PRO_MACHINE = "准备3";

	
//	private static String PRO_MACHINE = "׼������";
	
	private static String FILE_PATH = Environment.getExternalStorageDirectory()
										.getAbsolutePath() + "/hoperun/setting.txt";
	
//	static {
//		parseXml();
//	}
	
	
	public static String getUrl() {
		return URL;
	}
	
	public static int getSocketTimeout() {
		return SOCKET_TIMEOUT;
	}
	
	public static int getRequestRate() {
		return REQUEST_RATE;
	}
	
	public static int getPageRate () {
		return FRESH_PAGE_RATE;
	}
	
	public static int getRowNum () {
		return ROW_NUM;
	}
	
	public static int getColumnNum () {
		return COLUMN_NUM;
	}
	public static String getProMachine() {
		return PRO_MACHINE;
	}
	
	/**
	 * ���������ļ�
	 */
	public static void parseXml () {
		
		try {
			FileInputStream in = new FileInputStream(FILE_PATH);
			XmlPullParser parser = Xml.newPullParser();
			parser.setInput(in, "utf-8");
			int eventType = parser.getEventType();
			while(eventType != XmlPullParser.END_DOCUMENT) {
				
				if(eventType == XmlPullParser.START_TAG) {
					String name = parser.getName();
					if(name.equalsIgnoreCase("url")) {
						
						setUrl(parser.nextText());
					} else if(name.equalsIgnoreCase("socketTimeout")) {
						
						setRequestTimeout(Integer.parseInt(parser.nextText()));
					} else if (name.equalsIgnoreCase("requestRate")) {
						
						setRequestRate(Integer.parseInt(parser.nextText()));
					} else if (name.equalsIgnoreCase("freshPageRate")) {
						
						setPageRate(Integer.parseInt(parser.nextText()));
					} else if (name.equalsIgnoreCase("prepared_rowNum")) {
						setRowNum(Integer.parseInt(parser.nextText()));
					} else if (name.equalsIgnoreCase("prepared_columnNum")) {
						setColumnNum(Integer.parseInt(parser.nextText()));
					}
					
				}
				eventType = parser.next();
			}
			
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	private static void setUrl(String url) {
		URL = url;
	}
	
	private static void setRequestTimeout(int requestTimeout) {
		SOCKET_TIMEOUT = requestTimeout;
	}
	
	private static void setRequestRate(int requestRate) {
		REQUEST_RATE = requestRate;
	}
	
	private static void setPageRate(int pageRate) {
		FRESH_PAGE_RATE = pageRate;
	}
	
	private static void setRowNum(int num) {
		ROW_NUM = num;
	}
	
	private static void setColumnNum(int num) {
		COLUMN_NUM = num;
	}
	
	private static void setProMachine(String machine) {
		PRO_MACHINE = machine;
	}
	
}
